<?php

class ApiAction extends Action {
    public function __construct() {
        parent::__construct();
        if (!logined()) redirect(U('Login/index'));
    }

    // 返回session json
    public function session() {
        $this->ajaxReturn(
            D('Session')->select(),
            'JSON'
        );
    }
    // 返回department json
    public function department() {
        $results = D('Department')->select();
        $data = array();
        foreach ($results as $re) {
            $data[$re['session_id']][] = $re;
        }
        $this->ajaxReturn($data, 'JSON');
    }
    // 返回department json
    public function post() {
        $results = D('Post')->select();
        $data = array();
        foreach ($results as $re) {
            $data[$re['department_id']][] = $re;
        }
        $this->ajaxReturn($data, 'JSON');
    }


    public function departmentById($id) {
        $this->ajaxReturn(
            D('Department')->where(array(
                'session_id' => $id
            ))->select(),
            'JSON'
        );
    }
    public function postById($id) {
        $this->ajaxReturn(
            D('Post')->where(array(
                'department_id' => $id
            ))->select(),
            'JSON'
        );
    }
}
